
<?php
	class xl_dia_diem extends database
	{
		function danhSachDiaDiem()
		{
			$this->setQuerry('select * from diadiem');
			$result = $this->loadAllRow();
			return $result;
		}
		// danh sách địa điểm theo mã người dùng
		
		function danhSachDiaDiemTheoMaNguoiDung($manguoidung)
		{
			$this->setQuerry("select * from diadiem, quanhuyen, tinhthanh where quanhuyen.maquanhuyen=diadiem.maquanhuyen and tinhthanh.matinhthanh=diadiem.matinhthanh and diadiem.manguoidung=".$manguoidung."");
			$result = $this->loadAllRow();
			return $result;
		}
		
		// thuỳ
		
		function danhSachDiaDiemTheoMaNguoiDung_First($manguoidung)
		{
			$this->setQuerry("select * from diadiem, quanhuyen, tinhthanh where quanhuyen.maquanhuyen=diadiem.maquanhuyen and tinhthanh.matinhthanh=diadiem.matinhthanh and diadiem.manguoidung=".$manguoidung." order by diadiem.madiadiem ASC limit 0,10");
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachDiaDiemTheoMaNguoiDung_ViewMore($manguoidung,$madiadiem)
		{
			$this->setQuerry("select * from diadiem, quanhuyen, tinhthanh where quanhuyen.maquanhuyen=diadiem.maquanhuyen and tinhthanh.matinhthanh=diadiem.matinhthanh and diadiem.manguoidung=".$manguoidung." and diadiem.madiadiem >".$madiadiem." order by diadiem.madiadiem limit 0,10");
			$result = $this->loadAllRow();
			return $result;
		}
		
		//
		//**************************khánh***********************************//
		function countAdvance($str){
			$this->setQuerry($str);
			$result = $this->loadAllRow();
			return count($result);
		}
		function advanceS($str){
			$this->setQuerry($str);
			$result = $this->loadAllRow();
			return $result;
		}
		function visitCount($madiadiem){
			$this->setQuerry("select SoNguoiDaDen from diadiem where MaDiaDiem = '$madiadiem'");
			$result = $this->loadAllRow();
			return $result[0]['SoNguoiDaDen'];
		}
		function updateView($madiadiem){
			$this->setQuerry("update diadiem set soluotxem = soluotxem + 1 where MaDiaDiem = '$madiadiem'");
			$result=$this->querry();
			return $result;
		}
		function updateVisit($madiadiem){
			$this->setQuerry("update diadiem set SoNguoiDaDen = SoNguoiDaDen + 1 where MaDiaDiem = '$madiadiem'");
			$result=$this->querry();
			return $result;
		}
		function dsDiaDiemMoiNhat(){
			$this->setQuerry("select*from diadiem order by madiadiem DESC limit 0,10");
			$result = $this->loadAllRow();
			return $result;
		}
		function dsDiaDiemMoiCapNhat($manhomdiadiem){
			$this->setQuerry("select*from diadiem where manhomdiadiem='$manhomdiadiem' order by madiadiem DESC limit 0,10");
			$result = $this->loadAllRow();
			return $result;
		}
		function dsDiaDiemTheoNhom_ViewMore_First($manhomdiadiem)
		{
			$this->setQuerry("select*from diadiem where manhomdiadiem =".$manhomdiadiem." limit 10");
			$result = $this->loadAllRow();
			return $result;
		}
		function  dsDiaDiemTheoNhom_ViewMore_Next($manhomdiadiem,$madiadiem){
			$this->setQuerry("select*from diadiem where manhomdiadiem = ".$manhomdiadiem." and madiadiem > ".$madiadiem ." limit 10");

			$result = $this->loadAllRow();
			return $result;
		}
		function tongDiaDiem($manhomdiadiem){
			$this->setQuerry("select madiadiem from diadiem where manhomdiadiem = $manhomdiadiem");
			$result = $this->loadAllRow();
			return $result;
		}
		function diaDiem($id){
			$this->setQuerry("select * from diadiem where MaDiaDiem = '$id'");
			$result = $this->loadAllRow();
			return $result;
		}
		function capNhatViTri($id,$lat,$lng){
			$this->setQuerry("update diadiem set KinhDo = '$lng',ViDo = '$lat' where MaDiaDiem='$id'");
			$result=$this->querry();
			return $result;
		}
		
		function placeOfGroup($manhomdiadiem,$madiadiem)
		{
			$this->setQuerry("select*from diadiem where manhomdiadiem =".$manhomdiadiem." and madiadiem <> '$madiadiem' order by MaDiaDiem DESC limit 10");
			$result = $this->loadAllRow();
			return $result;
		} 

		//***********************************[end] khánh*********************//
		
		//Jenny
		function danhSachDiaDiemTheoNhom($manhomdiadiem)
		{
			$this->setQuerry("select*from diadiem where manhomdiadiem =".$manhomdiadiem." order by soluotxem DESC limit 0,4");
			$result = $this->loadAllRow();
			return $result;
		} 
		
		function danhSachDiaDiemTheoNhom1($manhomdiadiem)
		{
			$this->setQuerry("select*from diadiem where manhomdiadiem =".$manhomdiadiem." order by soluotxem DESC");
			$result = $this->loadAllRow();
			return $result;
		} 
		//
		function themDiaDiemChinhSua($tendiadiem,$diachi,$kinhdo,$vido,$mota,$sodienthoai,$website,$songuoidaden,$soluotxem,$manguoidung,$matinhthanh,$maquanhuyen,$manhomdiadiem)
		{
			$this->setQuerry("insert into diadiem values('$tendiadiem','$diachi','$kinhdo','$vido','$mota','$sodienthoai','$website','$songuoidaden','$soluotxem','$manguoidung','$matinhthanh','$maquanhuyen','$manhomdiadiem')");
			$result=$this->querry();
			return $result;
		}
		function themDiaDiem($tendiadiem,$diachi,$kinhdo,$vido,$mota,$sodienthoai,$website,$manguoidung,$matinhthanh,$maquanhuyen,$manhomdiadiem)
		{
			$this->setQuerry("insert into diadiem(TenDiaDiem,DiaChi,KinhDo,ViDo,MoTa,SoDienThoai,Website,MaNguoiDung,MaTinhThanh,MaQuanHuyen,MaNhomDiaDiem) values('$tendiadiem','$diachi','$kinhdo','$vido','$mota','$sodienthoai','$website','$manguoidung','$matinhthanh','$maquanhuyen','$manhomdiadiem')");
			$result=$this->querry();
			return $result;
		}
		function capNhatDiaDiem($madiadiem,$ten,$diachi,$kinhdo,$vido,$mota,$dienthoai,$web,$matinh,$maquan,$manhom)
		{
			$this->setQuerry("update diadiem set TenDiaDiem='$ten', DiaChi='$diachi', KinhDo='$kinhdo', ViDo='$vido', MoTa='$mota', SoDienThoai='$dienthoai', Website='$web', MaTinhThanh='$matinh', MaQuanHuyen='$maquan', MaNhomDiaDiem='$manhom' where MaDiaDiem='$madiadiem'");
			$result=$this->querry();
			return $result;
		}
		function xoaDiaDiem($madiadiem)
		{
			$this->setQuerry("delete from diadiem where MaDiaDiem=$madiadiem");
			$result=$this->querry();
			return $result;
		}
	}
?>